<?php
$this->breadcrumbs = array(
	'凭证统计报表' => array(
		'stat'
	),
	'多期统计'
);

?>

<h1>多期统计</h1>
<div class="form">
<?php $form = $this
	->beginWidget('CActiveForm',
		array(
			'action' => Yii::app()->createUrl($this->route),
			'method' => 'get',
		));
?>

<fieldset>
<legend>搜索条件</legend>

	<?php echo $form->errorSummary($statModel); ?>
	<div class="row">
		<?php echo $form->labelEx($statModel, 'projectId'); ?>
		<?php echo $form
			->dropDownList($statModel, 'projectId',
				CHtml::listData(AccountTokenProject::getAll(), 'id', 'name'),
				array(
					'empty' => '所有公司账目'
				));
		?>
		<?php echo $form->error($statModel, 'projectId'); ?>
	</div>
	<div class="row">
		<?php echo $form->label($statModel, 'tokenDateStart'); ?>
		<?php $this
			->widget('zii.widgets.jui.CJuiDatePicker',
				array(
					'model' => $statModel,
					'attribute' => 'tokenDateStart',
				));
		?> - 
		<?php $this
			->widget('zii.widgets.jui.CJuiDatePicker',
				array(
					'model' => $statModel,
					'attribute' => 'tokenDateEnd',
				));
		?>
	</div>
	<div class="row buttons">
		<?php echo CHtml::submitButton('确定'); ?>
	</div>

</fieldset>
<?php $this->endWidget(); ?>
</div>
<?php
if ($statModel->validate()) {
?>
<div id="stat-container"></div>
<?php
	$dataUrl = CJSON::encode($this->createUrl('statMultiPeriodData'));
	$baseParams = CJSON::encode($statModel->attributes);
	$overallStat = CJSON::encode($overallStat);
	$viewUrl = CJSON::encode($this->createUrl('view', array(
			'id' => '_token_id_'
		)));
	$script = <<<EOF
Ext.onReady(function(){
	Ext.define('JX.Model.Account.Token.SinglePeriodStat', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id',     type: 'int'},
            {name: 'tokenId',     type: 'int'},
            {name: 'name',     type: 'string'},
            {name: 'lastSum',     type: 'float'},
            {name: 'lastDirection', type: 'string'},
            {name: 'totalDebit',     type: 'float'},
            {name: 'totalCredit', type: 'float'},
            {name: 'direction', type: 'string'},
            {name: 'currentSum', type: 'float'},
            {name: 'totalSum', type: 'float'},
            {name: 'totalDirection', type: 'string'},
            {name: 'leaf', type: 'boolean'},
            {name: 'iconCls', type: 'string'}
        ]
    });

    var store = Ext.create('Ext.data.TreeStore', {
        model: 'JX.Model.Account.Token.SinglePeriodStat',
        proxy: {
            type: 'ajax',
            url: $dataUrl
        }
    });

    var tree = Ext.create('Ext.tree.Panel', {
        title: '多期报告 {$statModel->tokenDateStart}-{$statModel->tokenDateEnd}',
        width: '100%',
        height: 550,
        renderTo: 'stat-container',
        collapsible: false,
        useArrows: true,
        rootVisible: false,
        store: store,
        multiSelect: false,
        singleExpand: false,
        resizable: 's',
        listeners:{
			beforeload: function(store, operation, options){
				operation.params=Ext.apply(operation.params,$baseParams);
			}
		},
        columns: [{
            xtype: 'treecolumn',
            text: '科目',
            flex: 5,
            sortable: false,
            dataIndex: 'name'
        },{
            text: '前期',
        	align: 'center',
            flex: 1,
            dataIndex: 'lastDirection',
            sortable: false
        },{
        	xtype:'numbercolumn',
        	align: 'right',
            text: '前期余额',
            flex: 2,
            dataIndex: 'lastSum',
            sortable: false
        },{
        	xtype:'numbercolumn',
        	align: 'right',
            text: '借方',
            flex: 2,
            dataIndex: 'totalDebit',
            sortable: false
        },{
        	xtype:'numbercolumn',
        	align: 'right',
            text: '贷方',
            flex: 2,
            dataIndex: 'totalCredit',
            sortable: false
        },{
            text: '方向',
        	align: 'center',
            flex: 1,
            dataIndex: 'direction',
            sortable: false
        },{
        	xtype:'numbercolumn',
            text: '额度',
        	align: 'right',
            flex: 2,
            dataIndex: 'currentSum',
            sortable: false
        },{
            text: '余额',
        	align: 'center',
            flex: 1,
            dataIndex: 'totalDirection',
            sortable: false
        },{
        	xtype:'numbercolumn',
            text: '余额数量',
        	align: 'right',
            flex: 2,
            dataIndex: 'totalSum',
            sortable: false
        }]
    });
});
EOF;
	Yii::app()->clientScript
		->registerScript('account-stat-single', $script, CClientScript::POS_END);
}
?>
